<?php

namespace Acme\DemoBundle\Repository;

use Doctrine\ORM\EntityRepository;

class LuongRepository extends EntityRepository
{
	public function saveChucVu($LuongTmp) {
		$em = $this->getEntityManager();
		$em = $this->getDoctrine()->getManager();
		$query = $em->createQuery(
				'SELECT p FROM AcmeStoreBundle:Product p WHERE p.price > :price ORDER BY p.price ASC'
		)->setParameter('price', '19.99');
		
		$products = $query->getResult();
		
		$em->persist($LuongTmp);
		
		
		$em->flush();
		$em = $this->getDoctrine()->getEntityManager();
		
		// suspend auto-commit
		$em->getConnection()->beginTransaction();
		
		// Try and make the transaction
		try {
			// Get the account
			$account = $this->getDoctrine()->getRepository('AcmeStoreBundle:Account')->find($id);
		
			// Lower balance
			$account->setBalance($account->getBalance() - 100);
		
			// Save account
			$em->persist($account);
			$em->flush();
		
			// Try and commit the transaction
			$em->getConnection()->commit();
		} catch (Exception $e) {
			// Rollback the failed transaction attempt
			$em->getConnection()->rollback();
			throw $e;
		}
	}
}